package com.gxa.controller;

import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.Result;
import com.gxa.domain.dto.FindUserByNameDTO;
import com.gxa.domain.dto.LoginFormDTO;
import com.gxa.domain.entity.User;
import com.gxa.service.Impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/user")
public class UserController {
    /*
    * 测试
    *
    * */
    @Autowired
    UserServiceImpl userService;

    @PostMapping("/add")//处理post请求，路径为/user/add
    public Result addUser(@RequestBody User user) {
        return userService.add(user); // 返回表示操作结果的result对象
    }

    @RequestMapping("findUserById")
    @ResponseBody
    public User findUserById(int userId){
        return userService.findUserById(userId);
    }

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ResponseBody
    public Result login(@RequestBody LoginFormDTO loginFormDTO){
        return userService.login(loginFormDTO);
    }

    /*
    * 根据用户名模糊查询
    * */
    @RequestMapping(value = "/findUserByName",method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson findUserByName(String title,int page,int limit){

        System.out.println(title+page+limit);

        return userService.findUserByName(title,page,limit);
    }
    @RequestMapping(value = "/findUserAll",method = RequestMethod.GET)
    @ResponseBody
    public LayuiResultJson findUserAll(int page, int limit){

        String title = "";
        System.out.println(title+page+limit);

        return userService.findUserByName(title,page,limit);
    }

}
